package com.qiyi.player.base.uuid
{
   import com.qiyi.player.base.rpc.RemoteObjectEvent;
   import com.qiyi.player.base.pub.EnumItem;
   import flash.events.Event;
   import com.qiyi.player.base.rpc.RemoteObjectStatusEnum;
   import com.qiyi.player.base.utils.UUID;
   
   public class RemoteUUID extends BaseUUID
   {
      
      public function RemoteUUID(param1:String) {
         super("RemoteUUID",param1);
      }
      
      public static const Evt_Success:String = "loadSuccess";
      
      private var _remote:UUIDProxy;
      
      private var _inited:Boolean = false;
      
      override public function load(param1:String = "") : void {
         super.load("");
         if(_uuid == null || !(_uuid.length == 32))
         {
            this.loadFromServer();
         }
      }
      
      private function loadFromServer() : void {
         if(this._remote)
         {
            this._remote.removeEventListener(RemoteObjectEvent.Evt_StatusChanged,this.onStatusChanged);
            this._remote.destroy();
         }
         this._remote = new UUIDProxy();
         this._remote.addEventListener(RemoteObjectEvent.Evt_StatusChanged,this.onStatusChanged);
         this._remote.initialize();
      }
      
      private function onStatusChanged(param1:RemoteObjectEvent) : void {
         super.load();
         var _loc2_:Object = this._remote.getData();
         var _loc3_:EnumItem = this._remote.status;
         this._remote.removeEventListener(RemoteObjectEvent.Evt_StatusChanged,this.onStatusChanged);
         this._remote.destroy();
         this._remote = null;
         if(_uuid)
         {
            this.dispatchEvent(new Event(Evt_Success));
            return;
         }
         _isNewUser = true;
         if(_loc3_ == RemoteObjectStatusEnum.Success)
         {
            _uuid = _loc2_ as String;
         }
         else
         {
            _uuid = UUID.createUUID();
         }
         this.save();
         this.dispatchEvent(new Event(Evt_Success));
      }
      
      override public function save() : void {
         super.save();
      }
   }
}
import com.qiyi.player.base.rpc.impl.BaseRemoteObject;
import com.qiyi.player.base.logging.ILogger;
import flash.net.URLRequest;
import flash.events.Event;
import com.adobe.serialization.json.JSON;
import com.qiyi.player.base.rpc.RemoteObjectStatusEnum;
import com.qiyi.player.base.logging.Log;

class UUIDProxy extends BaseRemoteObject
{
   
   function UUIDProxy() {
      this._log = Log.getLogger("com.qiyi.player.core.model.uuid");
      super(0,"UUIDServer");
      this._timeout = 2000;
      _retryMaxCount = 2;
   }
   
   protected var _log:ILogger;
   
   override protected function getRequest() : URLRequest {
      return new URLRequest("http://data.video.qiyi.com/uid");
   }
   
   override protected function onComplete(param1:Event) : void {
      var obj:Object = null;
      var event:Event = param1;
      var strContent:String = _loader.data;
      var indexLift:int = strContent.indexOf("{");
      var indexRight:int = strContent.indexOf("}",-1);
      strContent = strContent.slice(indexLift,indexRight + 1);
      try
      {
         obj = com.adobe.serialization.json.JSON.decode(strContent);
         this._data = obj.uid;
         super.onComplete(event);
      }
      catch(e:Error)
      {
         _log.info("failed to parse serverUUID: " + _loader.data.substr(0,100));
         this.setStatus(RemoteObjectStatusEnum.DataError);
      }
   }
}
